package chapter06

/**
  * scala构造器
  */
object Test05_Constructor {

  def main(args: Array[String]): Unit = {

    val teacher1 = new Teacher1(444,"张三",55)
    println(s"${teacher1.name}")
    val teacher2 = new Teacher2
    println(teacher2.name)
  }
}

// 有参构造器,定义属性,var 说明是属性，否则是局部变量
class Teacher1(var id: Long,  var name: String,var  age: Int) {



}

// 无参构造器
class Teacher2 {
  // 定义属性
  var id: Long = _
  var name: String = _
  var age: Int = _
  println("1.major constructor is using")

  // 声明辅助构造器

  def this(name: String,age:Int) {
    this()
    println("2.minor constructor is using")
    this.name = name
    this.age = age
    println(s"name:$name")
  }
  // 声明辅助构造器
  def this(name: String) {
    this()
    println("2.minor constructor is using")
    this.name = name
    println(s"name:$name")
  }

}
